package com.chinasofti.Servlet;

import com.chinasofti.po.Data;
import com.chinasofti.util.GetFileClass;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/first")
public class FirstServelt extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("txt/html;charset=UTF-8");
        JSONObject obj=new JSONObject();
        List<Data> datas= GetFileClass.readData();
        obj.put("data", JSONArray.fromObject(datas));
        response.getWriter().write(obj.toString());
    }
}
